package www.openteam.com.model.business;

import android.util.Log;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.schedulers.Schedulers;
import www.openteam.com.api.UserManager;
import www.openteam.com.bean.ApprovalStatu;
import www.openteam.com.bean.InsertStatus;

/**
 * Created by kylin on 2016/12/2.
 * 更新客户信息子项Model
 */

public class UpdateCustomOrderItemInfoModelImpl implements UpdateCustomOrderItemInfoModel {

    private static final String TAG = UpdateCustomOrderItemInfoModelImpl.class.getSimpleName();
    private UpdateCustomOrderInfoOnListener updateCustomOrderInfoOnListener;

    public UpdateCustomOrderItemInfoModelImpl(UpdateCustomOrderInfoOnListener updateCustomOrderInfoOnListener) {
        this.updateCustomOrderInfoOnListener = updateCustomOrderInfoOnListener;
    }

    @Override
    public void updateCustomOrderItemInfo(int id, String prodno, String wraptype, String paperinf, String senddate, String technicsinf, String printcolor, String paynumb, String othernumb, String price, String eprodno) {

        UserManager.updateCustomOrderItemInfo(id, prodno, wraptype, paperinf, senddate, technicsinf, printcolor, paynumb, othernumb, price, eprodno)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<ApprovalStatu>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        Log.d(TAG, "onError: " + e.getMessage());
                        Log.d(TAG, "onError: " + "sadd" +
                                "");
                        updateCustomOrderInfoOnListener.updateCOIFail(e);
                    }

                    @Override
                    public void onNext(ApprovalStatu updateStatu) {
                        Log.d(TAG, "onNext: " + updateStatu);
                        updateCustomOrderInfoOnListener.updateCOISuccess(updateStatu);
                    }
                });
    }

    @Override
    public void insertCustomOrderItemInfo(int id, String prodno, String wraptype, String paperinf, String senddate, String technicsinf, String printcolor, String paynumb, String othernumb, String price) {
        UserManager.insertCustomOrderItemInfo(id, prodno, wraptype, paperinf, senddate, technicsinf, printcolor, paynumb, othernumb, price)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<ApprovalStatu>() {
                    @Override
                    public void onCompleted() {
                    }

                    @Override
                    public void onError(Throwable e) {
                        Log.d(TAG, "onError: " + e.getMessage());
                        Log.d(TAG, "onError: " + "sadd" +
                                "");
                        updateCustomOrderInfoOnListener.updateCOIFail(e);
                    }

                    @Override
                    public void onNext(ApprovalStatu updateStatu) {
                        Log.d(TAG, "onNext: " + updateStatu);
                        updateCustomOrderInfoOnListener.updateCOISuccess(updateStatu);
                    }
                });
    }

    @Override
    public void updateCustomOrderMainInfo(int id, String rdsno, String custid, String userid, String moneytype, String paytime, String sendtype, String custorderid, String alreadlypay, String inputdate, String inputer, String orderamount, String remark, String orderdate, String sendaddress, String istax, String taxrate, String invtype, String stype) {
        UserManager.updateCustomOrderMainInfo(id, rdsno, custid, userid, moneytype, paytime, sendtype, custorderid, alreadlypay, inputdate, inputer, orderamount, remark, orderdate, sendaddress, istax, taxrate, invtype, stype)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<ApprovalStatu>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        Log.d(TAG, "onError: " + e.getMessage());
                        Log.d(TAG, "onError: " + "sadd" +
                                "");
                        updateCustomOrderInfoOnListener.updateCOMIFail(e);
                    }

                    @Override
                    public void onNext(ApprovalStatu updateStatu) {
                        Log.d(TAG, "onNext: " + updateStatu);
                        updateCustomOrderInfoOnListener.updateCOMISuccess(updateStatu);
                    }
                });
    }


    public interface UpdateCustomOrderInfoOnListener {

        void updateCOISuccess(ApprovalStatu updateState);

        void updateCOIFail(Throwable throwable);

        void updateCOMISuccess(ApprovalStatu updateState);

        void updateCOMIFail(Throwable throwable);
    }
}
